$(document).ready(function(){
    var help_dialog = $( "#help_dialog" ).dialog({
        autoOpen: false,
        modal: true,
        width : "auto",
        buttons: {
            Ok: function() {
                $( this ).dialog( "close" );
            }
        }
    });
    
    $(".help").live("click", function(){
        help_dialog.dialog("open");
    });     
    
    
    var num_fournisseur = $(document).find('#num_fournisseur').text();
    
    var cookieName = 'accordionFournisseurShow'+num_fournisseur;
    
    var accordion = $( "#accordion" ).accordion({
        collapsible: true,
        autoHeight: false,
        active: ( $.cookies.get( cookieName ) || 0 ),
        change: function( e, ui )
        {
            $.cookies.set( cookieName, $( this ).find( 'h3' ).index ( ui.newHeader[0] ) );
        }
    });
    
    var listeFournisseur = $('#listeFournisseur').dataTable( {
        "bAutoWidth": false,
        "bJQueryUI": true,
        "bPaginate": true,
	"bSort": true,
        "bStateSave": true,
        "sPaginationType": "full_numbers",
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "fournisseur/list",
        "oLanguage":
        {
            "sUrl": "/datatable/language"
        },
        "aoColumnDefs": [ {"bSortable": false, "aTargets": [ 2, 4, 5 ]} ],
        "fnInitComplete": function(oSettings, json) {
            $('#listeFournisseur_filter').find(":text").qtip({
                content: $('#listeFournisseur_qtip'),
                position: {
                        my: 'bottom center', 
                        at: 'top center'
                },
                show: {
                    event: 'click',
                    effect: function() {
                        $(this).stop(0, 1).fadeIn(400);
                    }
                },
                hide: {
                    event: 'unfocus',
                    effect: function() {
                        $(this).stop(0, 1).fadeOut(400);
                    }
                },
                style: { 
                        tip: true,
                        classes: 'ui-tooltip-blue ui-tooltip-shadow ui-tooltip-rounded'
                }
            });  
        }
   });
   
   var idFournisseur = $('#listeEchantillons').attr("idfournisseur");
   
   var listeEchantillon = $('#listeEchantillons').dataTable( {
        "bAutoWidth": false,
        "bJQueryUI": true,
        "bPaginate": true,
	"bSort": true,
        "bStateSave": true,
        "sPaginationType": "full_numbers",
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "/fournisseur/listEchantillons",
        "oLanguage":
        {
            "sUrl": "/datatable/language"
        },
        "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 3, 6 ] } ],
        "fnServerParams": function ( aoData ) {
            aoData.push( { "name": "idFournisseur", "value": idFournisseur } );
        },
        "fnInitComplete": function(oSettings, json) {
            $('#listeEchantillons_filter').find(":text").qtip({
                content: $('#listeEchantillons_qtip'),
                position: {
                        my: 'bottom center', 
                        at: 'top center'
                },
                show: {
                    event: 'click',
                    effect: function() {
                        $(this).stop(0, 1).fadeIn(400);
                    }
                },
                hide: {
                    event: 'unfocus',
                    effect: function() {
                        $(this).stop(0, 1).fadeOut(400);
                    }
                },
                style: { 
                        tip: true,
                        classes: 'ui-tooltip-blue ui-tooltip-shadow ui-tooltip-rounded'
                }
            });  
        }
   });
   
});
